package com.tj.jinzao.presenter;

import com.tj.jinzao.api.SubscriberCallBack;
import com.tj.jinzao.base.BasePresenter;
import com.tj.jinzao.base.IBaseView;
import com.tj.jinzao.common.Constant;
import com.tj.jinzao.model.Article;
import com.tj.jinzao.model.Circle;
import com.tj.jinzao.model.CommentMessageBean;
import com.tj.jinzao.model.Message;
import com.tj.jinzao.model.ResultResponse;
import com.tj.jinzao.model.User;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * 消息处理
 * Created by wjy 2019/1/5.
 */
public class MessagePresenter extends BasePresenter<IBaseView<List<Article>>> {

    public MessagePresenter(IBaseView<List<Article>> view) {
        super(view);
    }
    public void getReplyMessageList(HashMap<String, Object> map) {
        addSubscription(mApiService.getMessageList(map), new SubscriberCallBack<List<Circle>>(mView.getContext()) {
            @Override
            protected void onSuccess(List<Circle> circles) {
                list.clear();
                for (int i=0;i<circles.size();i++){
                    circles.get(i).getCircle().setUser(circles.get(i).getUser());
                    circles.get(i).getCircle().setMessageType(circles.get(i).getType());
                    list.add(circles.get(i).getCircle());
                }
                if (mView != null) mView.onRequestSuccess(list);
            }

            @Override
            protected void onFailure(ResultResponse response) {
                if (mView != null) mView.onRequestError(response.getMessage());
            }

            @Override
            protected boolean isShowProgress() {
                return false;
            }
        });
    }
    private List<Article> list=new ArrayList<>();
    public void getAttentColAll(HashMap<String, Object> map) {
        addSubscription(mApiService.getAttentColAll(map), new SubscriberCallBack<List<Circle>>(mView.getContext()) {
            @Override
            protected void onSuccess(List<Circle> circles) {
                list.clear();
                for (int i=0;i<circles.size();i++){
                    circles.get(i).getCircle().setUser(circles.get(i).getUser());
                    circles.get(i).getCircle().setMessageType(circles.get(i).getType());
                    list.add(circles.get(i).getCircle());
                }
                if (mView != null) mView.onRequestSuccess(list);
            }

            @Override
            protected void onFailure(ResultResponse response) {
                if (mView != null) mView.onRequestError(response.getMessage());
            }

            @Override
            protected boolean isShowProgress() {
                return false;
            }
        });
    }

    public void getWMAboutMe(HashMap<String, Object> map) {
        addSubscription(mApiService.getWMAboutMe(map), new SubscriberCallBack<List<CommentMessageBean>>(mView.getContext()) {
            @Override
            protected void onSuccess(List<CommentMessageBean> commentMessageBeans) {
                list.clear();
                for (int i=0;i<commentMessageBeans.size();i++)
                {
                    commentMessageBeans.get(i).getCircle().setUser(commentMessageBeans.get(i).getUser());
                    commentMessageBeans.get(i).getCircle().setComment_content(commentMessageBeans.get(i).getContent());
                    list.add(commentMessageBeans.get(i).getCircle());
                }
                if (mView != null) mView.onRequestSuccess(list);
            }

            @Override
            protected void onFailure(ResultResponse response) {
                if (mView != null) mView.onRequestError(response.getMessage());
            }

            @Override
            protected boolean isShowProgress() {
                return false;
            }
        });
    }
    public void getWMessageList(HashMap<String, Object> map) {
        addSubscription(mApiService.getWMessageList(map), new SubscriberCallBack<List<Article>>(mView.getContext()) {
            @Override
            protected void onSuccess(List<Article> list) {
                if (mView != null) mView.onRequestSuccess(list);
            }

            @Override
            protected void onFailure(ResultResponse response) {
                if (mView != null) mView.onRequestError(response.getMessage());
            }

            @Override
            protected boolean isShowProgress() {
                return false;
            }
        });
    }



    public void getPraiseCollectMessageList() {
        //todo for test
        List<Message> list = new ArrayList();
        User user = new User();
        user.setNickname("孙一冰");
        user.setImgurl("http://g.hiphotos.baidu.com/image/s%3D550%3Bc%3Dwantu%2C8%2C95/sign=fec0811dd62a283447a6360e6b8eaad7/d6ca7bcb0a46f21f2090cf53f4246b600c33ae0e.jpg?referer=fba1a8e7932397dd8f6ead340a04");
        Message message = new Message();
        message.setTime(System.currentTimeMillis() - Constant.REQUEST_ONE_MONTH_TIME);
        message.setType(3);
        message.setHint("赞了你的日记");
        message.setImageUrl("http://b.hiphotos.baidu.com/image/s%3D550%3Bc%3Dwantu%2C8%2C95/sign=a1736326770e0cf3a4f74efe3a7d9122/908fa0ec08fa513d17b6a2ea386d55fbb2fbd9e2.jpg?referer=321aa0b1ccea15ce18f9d53927a0");
        message.setUser(user);
        Message message1 = new Message();
        message1.setTime(System.currentTimeMillis());
        message1.setType(4);
        message1.setUser(user);
        message1.setHint("收藏了你的视频");
        message1.setImageUrl("http://a.hiphotos.baidu.com/image/s%3D550%3Bc%3Dwantu%2C8%2C95/sign=6d46e4b2d739b60049ce0fb2d96b5617/0d338744ebf81a4c29870b98d52a6059252da62e.jpg?referer=a82ade9533adcbef58234a3602e4");
        list.add(message);
//        if (mView != null) mView.onRequestSuccess(list);
    }
}
